﻿using FairyGUI;

/// <summary>
/// 设置界面
/// </summary>
public class UIGameSetting : UIPopupWindow {

	public UIGameSetting()
    {
        // 加载界面
        base.Init(UIPackage.CreateObject("游戏界面", "设置界面").asCom);

        // 初始化关闭按钮
        GButton closeBtn = uiComp.GetChild("关闭按钮").asButton;
        closeBtn.onClick.Add(() => {
			_Close();
        });

		GSlider _musicEfCtrl = uiComp.GetChild("音效").asSlider;
		_musicEfCtrl.onChanged.Add(()=> {
			AudioController.inst.effectVolume = (float)(_musicEfCtrl.value * 0.01);
		});
		_musicEfCtrl.value = AudioController.inst.effectVolume * 100;


		GSlider _musicCtrl = uiComp.GetChild("音乐").asSlider;
		_musicCtrl.onChanged.Add(() => {
			AudioController.inst.musicVolume = (float)(_musicCtrl.value * 0.01);
		});
		_musicCtrl.value = AudioController.inst.musicVolume * 100;
    }

	public void _Close() {
		DebugInfo.Log("关闭设置");

		AudioController.inst.PlayUIClickEffect();
		AudioController.inst.SavePreference();
		uiComp.RemoveFromParent();
		uiComp.Dispose();
		base.Close();
	}

    /// <summary>
    /// 弹出窗口
    /// </summary>
    public static void Popup()
    {
        DebugInfo.Log("打开设置");
		UIRootController.inst.PopupWindow(new UIGameSetting());
    }
}
